<?php 
$db = JFactory::getDBO();
/*$session=JFactory::getSession();
//echo $session->get('height');die();
$db->setQuery("SELECT virtuemart_customfield_id FROM #__virtuemart_product_customfields WHERE custom_value='istraxx_customsize' and virtuemart_product_id = ".JRequest::getVar('virtuemart_product_id'));
$id = $db->loadResult();
$db->setQuery("SELECT product_special FROM #__virtuemart_products WHERE virtuemart_product_id = ".JRequest::getVar('virtuemart_product_id'));
$special=$db->loadResult();
?>
<?php if($special) : ?>
<script language="javascript">

$(document).ready(function() {
	jQuery('.istraxx_customsize<?php echo $id?>').attr('value','<?php echo $session->get('height')?>');
	//alert(jQuery('.istraxx_customsize48').val());
	jQuery('.istraxx_customsize<?php echo $id?>').keyup();
	
});

</script>
<?php endif;*/?>
 


<?php
	defined('_JEXEC') or die();
	$class='istraxx_customsize';
// 	vmdebug('this->params',$viewData);

	if(empty($this->params->cm_digitsa)){
		$this->params->cm_digitsa = 0;
	}

	if(empty($this->params->cm_digitsb)){
		$this->params->cm_digitsb = 0;
	}

	$currency = CurrencyDisplay::getInstance()->priceDisplay($viewData[0]->custom_price);
	$unitProductEdit = $this->params->cm_unit;
	if($this->params->cm_is_surface !=0) {
		$unitProductEdit .= '&sup2;';
	}
	echo JText::sprintf('VMCUSTOM_ISTRAXX_CUSTOMSIZE_PERUNIT',$currency,$this->params->cm_unit);
?>
<br />
	<input class="<?php echo $class.$viewData[0]->value ?>" type="text" value="<?php echo $this->params->cm_mina ?>" size="<?php echo $this->params->cm_size ?>" name="customPlugin[<?php echo $viewData[0]->value ?>][<?php echo $this->_name?>][invala]">
<?php
	$timeoutsjs ='';
	if($this->params->cm_is_surface !=0) {
?>		<input class="<?php echo $class.$viewData[0]->value ?>" type="text" value="<?php echo $this->params->cm_minb ?>" size="<?php echo $this->params->cm_size ?>" name="customPlugin[<?php echo $viewData[0]->value ?>][<?php echo $this->_name?>][invalb]">
<?php
	$timeoutsjs = 'setTimeout("checkLimits(\'invalb\','.$this->params->cm_digitsb.','.$this->params->cm_minb.','.$this->params->cm_maxb.',\''.JText::sprintf('VMCUSTOM_ISTRAXX_CUSTOMSIZE_LIMIT_MIN_REACHED',$this->params->cm_minb).'\',\''.JText::sprintf('VMCUSTOM_ISTRAXX_CUSTOMSIZE_LIMIT_MAX_REACHED',$this->params->cm_maxb).'\')", 1100);';
	} ?>
<br />
<?php

    $document = JFactory::getDocument();
	$document->addScriptDeclaration('
	jQuery(document).ready( function($) {

	jQuery("form .'.$class.$viewData[0]->value.'").keyup(function() {
	    

        formProduct = $(this).parents("form");
		virtuemart_product_id = formProduct.find(\'input[name="virtuemart_product_id[]"]\').val();
	    Virtuemart.setproducttype(formProduct,virtuemart_product_id);

        elem = formProduct.find(\'input[name="customPlugin['.$viewData[0]->value.']['.$this->_name.']["+elem+"]"]\');
		setTimeout("checkLimits(\'invala\','.$this->params->cm_digitsa.','.$this->params->cm_mina.','.$this->params->cm_maxa.',\''.JText::sprintf('VMCUSTOM_ISTRAXX_CUSTOMSIZE_LIMIT_MIN_REACHED',$this->params->cm_mina).'\',\''.JText::sprintf('VMCUSTOM_ISTRAXX_CUSTOMSIZE_LIMIT_MAX_REACHED',$this->params->cm_maxa).'\')", 1100);
		'.$timeoutsjs.'
	});
});
	');
	// preventing 2 x load javascript
	static $textinputjs;
	if ($textinputjs) return true;
	$textinputjs = true ;
	//javascript to update price
	$document->addScriptDeclaration('
function checkLimits(elem,digits,min,max,mmin,mmax){

	elem = formProduct.find(\'input[name="customPlugin['.$viewData[0]->value.']['.$this->_name.'][\'+elem+\']"]\');
	var size = elem.val();
	var rounded = Math.round(size*Math.pow(10,digits))/Math.pow(10,digits);

	if (rounded < min || isNaN(rounded)){
		elem.val(min);
		alert(mmin);
	} else if (rounded > max ) {
		elem.val(max);
		alert(mmax);
	} else {
		elem.val(rounded);
	}
};
');
